<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px" :disabled="disabled">
                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="提交用户:" prop="user_id">
                            <SelectPage v-model="form.user_id" :url="'/admin/user/selectPage'" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="需求描述:" prop="task_id">
                            <SelectPage v-model="form.task_id" :url="'/admin/pz.task/selectPage'" show_field="content" show_id="id" query_field="id" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="需求方电话:" prop="task_mobile">
                            <el-input v-model="form.task_mobile" placeholder="请输入需求方电话" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="合作方电话:" prop="partner_mobile">
                            <el-input v-model="form.partner_mobile" placeholder="请输入合作方电话" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="类型:" prop="type">
                            <el-select v-model="form.type" placeholder="请选择类型" clearable>
                                <el-option v-for="(item, index) in type" :key="index" :label="item.label" :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="状态:" prop="status">
                            <el-select v-model="form.status" placeholder="请选择状态" clearable>
                                <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="截图:" prop="images">
                            <ImageUpload v-model="form.images" :limit="10" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="描述:" prop="content">
                            <el-input type="textarea" :rows="4" v-model="form.content" placeholder="请输入描述" clearable />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item label="聊天记录:" prop=" ">
                    <chatList :userId="form.user_id" :targetUserId="form.partner_user_id"></chatList>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>
<script>
import { regionData } from 'element-china-area-data'
import chatList from './chatList.vue'
export default {
    name: 'EditForm',
    components: {chatList},
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {
                user_id: [{ required: true, message: "请输入用户id", trigger: "blur" }],
                task_id: [{ required: true, message: "请输入任务ID", trigger: "blur" }],
                task_mobile: [{ required: true, message: "请输入需求方电话", trigger: "blur" }],
                partner_mobile: [{ required: true, message: "请输入合作方电话", trigger: "blur" }],

            },
            form: {  },
            // 区域选择配置
            areaOptions: regionData,
            type:[
               { label: "需求方原因", value: 1 },
               { label: "合作方原因", value: 2 },
            ],
            status:[
               { label: "待处理", value: 1 },
               { label: "强制完成", value: 2 },
               { label: "取消订单", value: 3 },
            ],

        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },

        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },

        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
